import baseApi from '@/config/server/api/base.js'
import dt from '@dt/dt';

function list(params) {
  return baseApi.message.notification.list.fetch(params)
}

function readAll(params) {
  return baseApi.message.notification.readAll.fetch(params).then(res => {
    dt.notify.emit('messageReadChange')
  })
}

function read(id) {
  return baseApi.message.notification.read.fetch({ id }).then(res => {
    dt.notify.emit('messageReadChange')
  })
}

function hasUnread() {
  return baseApi.message.notification.hasUnread.fetch().then(res => {
    let ids = []
    res.noPopUpFramePersonalList.forEach(item => {
      ids.push(item.id)
    })
    if (ids.length > 0) {
      tip(ids.join(','))
    }
    return res
  })
}

function tip(ids) {
  return baseApi.message.notification.tip.fetch({ ids })
}

export default {
  list,
  hasUnread,
  readAll,
  read
}
